import moment from "moment"
import { getAllAnalysisComponentByEditType, updateAllAnalysisComponent } from "../lib/analysisData"
import { defaultBackgroundAttr } from "../lib/const"
import { deepCopy, ergodicList } from "../lib/utils"
import { getAllFilterComponentTypes } from "../lib/filter"

export default {
  handleReset: (vm, event) => {
    const {
      componentList,
      pageSetting
    } = vm.$store.state.lowCode.previewData
    const filterComponentTypes = getAllFilterComponentTypes()
    ergodicList(componentList, component => {
      if(filterComponentTypes.includes(component.type) ){ // && component.props.filterField?.length > 0
        let {
          value
        } = component.props
        if(value instanceof Array){
          value = []
        }
        else {
          value = null
        }
        component.props.value = value
      }
    })
    vm.$store.commit("lowCode/setPreviewData", {
      componentList,
      pageSetting
    })
    vm.$forceUpdate()
  },
  handleSubmit: (vm, event) => {
    const {
      componentList
    } = vm.$store.state.lowCode.previewData
    const filterComponentList = componentList.filter(component => component.type === "filter" && component.props.filterField?.length > 0)
    // 获取所有业务组件
    // const analysisComponentList = getAllAnalysisComponentByEditType()
    // 触发所有业务组件的更新
    updateAllAnalysisComponent()
    const filterData = {}
    // ergodicList(filterComponentList ,component => {
    //   const {
    //     filterField,
    //     format
    //   } = component.props
    //   let {
    //     value
    //   } = component.props
    //   if(component.tag.indexOf('picker') > -1 && value){
    //     if(value instanceof Array){
    //       value = value.map(date => window.moment(date).format(format))
    //     }
    //     else {
    //       if(value._d){
    //         value = window.moment(value).format(format)
    //       }

    //     }

    //   }
    //   if(value instanceof window.moment || value?._d){

    //   }
    //   filterData[filterField] = value
    // })
    console.log(filterData)
  }

}
